Music Object Extension - Clip
|
|
The Clip extension provides a set of services for conveniently creating a music preview system on a Web page.
|
What's New in the Latest Version
|
There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.
To get the "music-object-x-clip.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-clip.js" into an appropriate folder of the local copy of your Web site.
In case you have problems saving the file using the above link, the "music-object-x-clip.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.
In order to use this extension, the following JavaScript file(s) must first be sourced in...
- music-object.js (version 3.3.0 or higher)
For more information on using extensions, consult the section About Music Object Extensions.
| Name |
Short Description |
| Music.Clip Object Constructor |
| Music.Clip |
An object constructor that lets you create a new Music.Clip object instance. |
| Music.Clip Instance Methods |
| insertUI |
Lets you insert the user interface for a Music.Clip object instance at the position within the document where this method is called. |
| play |
Lets you play the music file that is loaded into a Music.Clip object instance. |
| stop |
Lets you stop the music file that is playing for a Music.Clip object instance. |
| Music.Clip Instance Properties |
| musicObject |
A reference to the Music Object instance that is used by a Music.Clip object instance. |
| Music.Clip Static Properties |
| Music.Clip.fadeOutTime |
An integer variable, specifying the default value that should be used for the FadeOutTimeINT parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.hoverDelay |
An integer variable, specifying the default value that should be used for the HoverDelayINT parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.hoverResetDelay |
An integer variable, specifying the default value that should be used for the HoverResetDelayINT parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.imagePath |
A string variable, specifying the URL path that is used to prefix all image URLs used by all Music.Clip object instances. |
| Music.Clip.imageHeight |
An integer variable, specifying the default value that should be used for the ImageHeightINT parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.imageUrl |
A string variable, specifying the default value that should be used for the ImageUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.imageWhileLoadingUrl |
A string variable, specifying the default value that should be used for the ImageWhileLoadingUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.imageWhilePlayingUrl |
A string variable, specifying the default value that should be used for the ImageWhilePlayingUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.imageWidth |
An integer variable, specifying the default value that should be used for the ImageWidthINT parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.instances |
An array of references to all the Music.Clip object instances that have been created in the document. |
| Music.Clip.musicUrl |
A string variable, specifying the default value that should be used for the MusicUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.restartIfPlaying |
A boolean variable, specifying the default value that should be used for the RestartIfPlayingBOOL parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.triggerType |
A string variable, specifying the default value that should be used for the TriggerTypeSTR parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.stopOnMouseOut |
A boolean variable, specifying the default value that should be used for the StopOnMouseOutBOOL parameter, if this parameter is not specified when creating Music.Clip object instances. |
| Music.Clip.stubPath |
A string variable, specifying the URL of the stub RMF file that is needed to instantiate the player instances used by all the Music.Clip object instances. |
| Static Methods |
| Music.newClips |
Provides a convenient way of creating multiple Music.Clip object instances in one single step. |
|
|
|
Music.Clip Object Constructor
|
The Music.Clip object constructor (a static method of the Music object) lets you create a new Music.Clip object instance.
|
Music.Clip (
ObjectNameSTR ,
MusicUrlSTR ,
ImageUrlSTR ,
ImageWhileLoadingUrlSTR ,
ImageWhilePlayingUrlSTR ,
ImageWidthINT ,
ImageHeightINT ,
TriggerTypeSTR ,
FadeOutTimeINT ,
StopOnMouseOutBOOL ,
RestartIfPlayingBOOL ,
HoverDelayINT ,
HoverResetDelayINT
)
|
|
ClipOBJ |

- ObjectNameSTR
Lets you specify the name of the Music.Clip object instance that should be created as a property of the window object. For instance, specifying the string value "myClip1" would allow you to reference the object instance in your code as window.myClip1 or just myClip1, as in the statement myClip1.insertUI ().
If you specify a name for this parameter that does not conform to the valid syntax for a JavaScript identifer (for example, if it contains spaces, hyphens, or other illegal characters), then you will need to perform a string dereference of the window object in order to access the Music.Clip object instance. As an example, if you specified the string value "My Clip - 1" for this parameter, then the object instance could be accessed as in the statement window ['My Clip - 1'].insertUI ().
- MusicUrlSTR
Lets you specify the URL of the music file that should be played for the Music.Clip object instance. If the value of this parameter is prefixed with an asterisk ('*'), then a URL will be created by using the remainder of the value, excluding the asterisk, to replace all occurrences of the characters '[*]' in the value of the Music.Clip.musicUrl static property. If the value of the paramater is not prefixed with an asterisk, then a URL will be created by using the value of the ObjectNameSTR parameter to replace all occurrences of the characters '[*]' in the value of the MusicUrlSTR parameter.
- ImageUrlSTR
Lets you specify the URL of the image file that should be displayed for the user interface of the Music.Clip object instance. If the value of this parameter is prefixed with an asterisk ('*'), then a URL will be created by using the remainder of the value, excluding the asterisk, to replace all occurrences of the characters '[*]' in the value of the Music.Clip.imageUrl static property. If the value of the paramater is not prefixed with an asterisk, then a URL will be created by using the value of the ObjectNameSTR parameter to replace all occurrences of the characters '[*]' in the value of the ImageUrlSTR parameter.
- ImageWhileLoadingUrlSTR
Lets you specify the URL of the image file that should be displayed for the user interface of the Music.Clip object instance, only while the music file is still loading in. If the value of this parameter is prefixed with an asterisk ('*'), then a URL will be created by using the remainder of the value, excluding the asterisk, to replace all occurrences of the characters '[*]' in the value of the Music.Clip.imageWhileLoadingUrl static property (or the value of the Music.Clip.imageUrl static property, if the Music.Clip.imageWhileLoadingUrl property is set to null). If the value of the paramater is not prefixed with an asterisk, then a URL will be created by using the value of the ObjectNameSTR parameter to replace all occurrences of the characters '[*]' in the value of the ImageWhileLoadingUrlSTR parameter.
- ImageWhilePlayingUrlSTR
Lets you specify the URL of the image file that should be displayed for the user interface of the Music.Clip object instance, only while the music file is playing. If the value of this parameter is prefixed with an asterisk ('*'), then a URL will be created by using the remainder of the value, excluding the asterisk, to replace all occurrences of the characters '[*]' in the value of the Music.Clip.imageWhilePlayingUrl static property (or the value of the Music.Clip.imageUrl static property, if the Music.Clip.imageWhilePlayingUrl property is set to null). If the value of the paramater is not prefixed with an asterisk, then a URL will be created by using the value of the ObjectNameSTR parameter to replace all occurrences of the characters '[*]' in the value of the ImageWhilePlayingUrlSTR parameter.
- ImageWidthINT
Lets you specify the width (measured in pixels) of the images that will be used for the user interface of the Music.Clip object instance.
- ImageHeightINT
Lets you specify the height (measured in pixels) of the images that will be used for the user interface of the Music.Clip object instance.
- TriggerTypeSTR
Lets you specify the triggering mode for the Music.Clip object instance. There are two possible values for this parameter...
- "click" - means that the music file will be played only when the user clisk on the user interface for the Music.Clip object instance.
- "over" - means that the music file will be played only when the user mouses over the user interface for the Music.Clip object instance.
- FadeOutTimeINT
Lets you specify the amount of time (measured in milliseconds) that a Music.Clip object instance's music file should take to completely fade out, each time that the instance is stopped. For example, a value of 2000 would mean that the clip would fade out to a stop over a period of 2 seconds (2000 milliseconds). Specifying a value of 0 for this parameter would result in an abrupt stop.
- StopOnMouseOutBOOL
Lets you specify whether or not a Music.Clip object instance's music file should automatically be stopped when the user mouses out of the instance's user interface.
- RestartIfPlayingBOOL
Lets you specify whether or not a Music.Clip object instance's music file should automatically be started again from the beginning if the instance is retriggered while the file is still playing.
- HoverDelayINT
Lets you specify the amount of time (measured in milliseconds) that the user needs to keep the mouse over the Music.Clip object instance's user interface in order to trigger the music file to play. This parameter only has meaning when the "over" trigger mode is being used. As an example, a value of 1000 would mean that the user would have to keep the mouse over the user interface for 1 second (1000 milliseconds) before the music file would start playing. Specifying a value of 0 for this parameter would cause the music file to begin playing immediately on mousing over the user interface.
- HoverResetDelayINT
Lets you specify the amount of time (measured in milliseconds) that it should take, after the the Music.Clip object instance's music file has completed fading out to a stop, before the Music.Clip object instance no longer registers that the user is hovering over the user interface, and the user has to then mouse over the user interface once again and hover for the amount of time specified by the HoverDelayINT parameter before the music file can be retriggered. This parameter only has meaning when the "over" trigger mode is being used.

- When a value of null is specified for the ObjectNameSTR parameter, then a value is automatically generated for this parameter. In this event, there would be no way for you to determine the value that has been chosen for this parameter, so the only way you would be able to reference the newly created Clip instance would be to assign the return value of the object constructor to a variable, as in the statement...
myClip = new Music.Clip (null,'my-clip-file.rmf')
Then you would be able to call methods of the Clip instance using this variable, as in the statement...
myClip.play ()
- When a value of null is specified for the MusicUrlSTR parameter, then this parameter is set to the value of the ObjectNameSTR parameter prefixed with an asterisk ('*'). So, if the ObjectNameSTR parameter were set to the string value "myClip", then the value "*myClip" would be used for the MusicUrlSTR parameter.
- When a value of null is specified for the ImageUrlSTR parameter, then this parameter is set to the value of the ObjectNameSTR parameter prefixed with an asterisk ('*'). So, if the ObjectNameSTR parameter were set to the string value "myClip", then the value "*myClip" would be used for the ImageUrlSTR parameter.
- When a value of null is specified for the ImageWhileLoadingUrlSTR parameter, then the value of the ImageUrlSTR parameter is used for this parameter.
- When a value of null is specified for the ImageWhilePlayingUrlSTR parameter, then the value of the ImageUrlSTR parameter is used for this parameter.
- When a value of null is specified for the ImageWidthINT parameter, then the value of the Music.Clip.imageWidth static property is used for this parameter.
- When a value of null is specified for the ImageHeightINT parameter, then the value of the Music.Clip.imageHeight static property is used for this parameter.
- When a value of null is specified for the TriggerTypeSTR parameter, then the value of the Music.Clip.triggerType static property is used for this parameter.
- When a value of null is specified for the FadeOutTimeINT parameter, then the value of the Music.Clip.fadeOutTime static property is used for this parameter.
- When a value of null is specified for the StopOnMouseOutBOOL parameter, then the value of the Music.Clip.stopOnMouseOut static property is used for this parameter.
- When a value of null is specified for the RestartIfPlayingBOOL parameter, then the value of the Music.Clip.restartIfPlaying static property is used for this parameter.
- When a value of null is specified for the HoverDelayINT parameter, then the value of the Music.Clip.hoverDelay static property is used for this parameter.
- When a value of null is specified for the HoverResetDelayINT parameter, then the value of the Music.Clip.hoverResetDelay static property is used for this parameter.

- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT , TriggerTypeSTR , FadeOutTimeINT , StopOnMouseOutBOOL , RestartIfPlayingBOOL , HoverDelayINT )
When no HoverResetDelayINT parameter is specified, then the value of the Music.Clip.hoverResetDelay static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT , TriggerTypeSTR , FadeOutTimeINT , StopOnMouseOutBOOL , RestartIfPlayingBOOL )
When there is also no HoverDelayINT parameter specified, then the value of the Music.Clip.hoverDelay static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT , TriggerTypeSTR , FadeOutTimeINT , StopOnMouseOutBOOL )
When there is also no RestartIfPlayingBOOL parameter specified, then the value of the Music.Clip.restartIfPlaying static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT , TriggerTypeSTR , FadeOutTimeINT )
When there is also no StopOnMouseOutBOOL parameter specified, then the value of the Music.Clip.stopOnMouseOut static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT , TriggerTypeSTR )
When there is also no FadeOutTimeINT parameter specified, then the value of the Music.Clip.fadeOutTime static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT , ImageHeightINT )
When there is also no TriggerTypeSTR parameter specified, then the value of the Music.Clip.triggerType static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR , ImageWidthINT )
When there is also no ImageHeightINT parameter specified, then the value of the Music.Clip.imageHeight static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR , ImageWhilePlayingUrlSTR )
When there is also no ImageWidthINT parameter specified, then the value of the Music.Clip.imageWidth static property is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR , ImageWhileLoadingUrlSTR )
When there is also no ImageWhilePlayingUrlSTR parameter specified, then the value of the ImageUrlSTR parameter is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR , ImageUrlSTR )
When there is also no ImageWhileLoadingUrlSTR parameter specified, then the value of the ImageUrlSTR parameter is used for this parameter.
- Music.Clip ( ObjectNameSTR , MusicUrlSTR )
When there is also no ImageUrlSTR parameter specified, then this parameter is set to the value of the ObjectNameSTR parameter prefixed with an asterisk ('*'). So, if the ObjectNameSTR parameter were set to the string value "myClip", then the value "*myClip" would be used for the ImageUrlSTR parameter.
- Music.Clip ( ObjectNameSTR )
When there is also no MusicUrlSTR parameter specified, then this parameter is set to the value of the ObjectNameSTR parameter prefixed with an asterisk ('*'). So, if the ObjectNameSTR parameter were set to the string value "myClip", then the value "*myClip" would be used for the MusicUrlSTR parameter.
|
Music.Clip Instance Methods
|
The insertUI instance method of the Music.Clip object lets you insert the user interface for a Music.Clip object instance at the position within the document where this method is called.
|
insertUI ( LinkHrefSTR , LinkTargetSTR , LinkAltSTR ) |

- When a value of null is specified for the LinkHrefSTR parameter, then the icon for the Music.Clip object instance will have no action for when the user clicks on it.
- When a value of null is specified for the LinkTargetSTR parameter, then any link that is specified (by the LinkHrefSTR parameter) for the icon of the Music.Clip object instance will target the current window / frame.
- When a value of null is specified for the LinkAltSTR parameter, then the icon for the Music.Clip object instance will display no alternate text while its image loads in, and will also display no tooltip when the user mouses over it.

- insertUI ( LinkHrefSTR , LinkTargetSTR )
When no LinkAltSTR parameter is specified, then the icon for the Music.Clip object instance will display no alternate text while its image loads in, and will also display no tooltip when the user mouses over it.
- insertUI ( LinkHrefSTR )
When there is also no LinkTargetSTR parameter specified, then any link that is specified (by the LinkHrefSTR parameter) for the icon of the Music.Clip object instance will target the current window / frame.
- insertUI ( )
When there is also no LinkHrefSTR parameter specified, then the icon for the Music.Clip object instance will have no action for when the user clicks on it.
The play instance method of the Music.Clip object lets you play the music file that is loaded into a Music.Clip object instance.
This method can be useful if you are not using the insertUI instance method in order to create the user interface for a Music.Clip object instance, but are instead creating your own custom interface.


- A Music.Clip object instance can be stopped using the instance's stop method.
The stop instance method of the Music.Clip object lets you stop the music file that is playing for a Music.Clip object instance.
|
stop ( ) |
This method can be useful if you are not using the insertUI instance method in order to create the user interface for a Music.Clip object instance, but are instead creating your own custom interface.

- A Music.Clip object instance can be triggered to play using the instance's play method.
|
Music.Clip Instance Properties
|
The musicObject instance property of the Music.Clip object is a reference to the Music Object instance that is used by a Music.Clip object instance.
This property can be useful if there are other ways you would like to control the playback of a clip while it is playing, or if you'd like to indicate playback state for clips using your own custom code. As an example, you could create custom code to hook into the onPlay and onStop callbacks for the Music Object instances of all Music.Clip object instances, so as to update the window's status bar to indicate when clips are playing.
The following sample code listing shows how this could be achieved...
for (var clipNo = 0; clipNo < Music.Clip.instances.length; clipNo++) {
var clipMO = Music.Clip.instances [clipNo].musicObject;
clipMO.addCallbackHandler ('onPlay','window.status = "audio preview clip playing..."');
clipMO.addCallbackHandler ('onStop','window.status = window.defaultStatus');
}
|
If this code is placed in the document after all Music.Clip object instances have been created, then the window's status bar will be updated each time any one of the clips starts or stops playing.
|
Music.Clip Static Properties
|
The Music.Clip.fadeOutTime static property is an integer variable, specifying the default value that should be used for the FadeOutTimeINT parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.hoverDelay static property is an integer variable, specifying the default value that should be used for the HoverDelayINT parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.hoverResetDelay static property is an integer variable, specifying the default value that should be used for the HoverResetDelayINT parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.imagePath static property is a string variable, specifying the URL path that is used to prefix all image URLs used by all Music.Clip object instances.
The Music.Clip.imageHeight static property is an integer variable, specifying the default value that should be used for the ImageHeightINT parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.imageUrl static property is a string variable, specifying the default value that should be used for the ImageUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.imageWhileLoadingUrl static property is a string variable, specifying the default value that should be used for the ImageWhileLoadingUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.imageWhilePlayingUrl static property is a string variable, specifying the default value that should be used for the ImageWhilePlayingUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.imageWidth static property is an integer variable, specifying the default value that should be used for the ImageWidthINT parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.instances static property is an array of references to all the Music.Clip object instances that have been created in the document.
This property can be useful if there is an operation that you would like to perform on all clips in the document. As an example, if you wanted to insert the user interfaces for all clips in an automated manner, you could simply iterate through all the elements of the Music.Clip.instances array, calling the insertUI method for each instance.
The following sample code listing shows how this could be achieved...
for (var clipNo = 0; clipNo < Music.Clip.instances.length; clipNo++) {
Music.Clip.instances [clipNo].insertUI ();
document.writeln ('<BR>');
}
|
Not only does such an approach save some code size, but nothing would need to be done to change this code in the future if more Music.Clip object instances were created or specific instances were removed.
In another example, if you were creating a preview page using the Clip extension and you also wanted to have background music playing on that page, then you could use the Ducking extension to wire the Music Object instances for all the clips to the Music Object instance that will be playing the background music. The code to do this might look as follows...
for (var clipNo = 0; clipNo < Music.Clip.instances.length; clipNo++) {
backgroundMO.addDuckingMasters (Music.Clip.instances [clipNo].musicObject);
}
|
In the above sample code snippet, it is assumed that the Clip extension and the Ducking extension have been sourced in, that all the Music.Clip object instances have been created, that the background music's Music Object instance has been created, etc.
The Music.Clip.musicUrl static property is a string variable, specifying the default value that should be used for the MusicUrlSTR parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.restartIfPlaying static property is a boolean variable, specifying the default value that should be used for the RestartIfPlayingBOOL parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.triggerType static property is a string variable, specifying the default value that should be used for the TriggerTypeSTR parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.stopOnMouseOut static property is a boolean variable, specifying the default value that should be used for the StopOnMouseOutBOOL parameter, if this parameter is not specified when creating Music.Clip object instances.
The Music.Clip.stubPath static property is a string variable, specifying the URL of the stub RMF file that is needed to instantiate the player instances used by all the Music.Clip object instances.
The Music.newClips static method provides a convenient way of creating multiple Music.Clip object instances in one single step.
|
Music.newClips ( ObjectName1STR , ObjectName2STR , ... , ObjectNameNSTR ) |
Calling the Music.newClips method essentially amounts to calling the Music.Clip object constructor multiple times, each time passing the next ObjectNameSTR parameter specified in the Music.newClips method's parameter list.
So, for example, the statement...
Music.newClips ('saphiku','bhapthala','tituli','laghlaza');
|
...would be equivalent to the block of statements...
new Music.Clip ('saphiku');
new Music.Clip ('bhapthala');
new Music.Clip ('tituli');
new Music.Clip ('laghlaza');
|

- When creating Music.Clip object instances using the Music.newClips method, it is not possible to specify the additional parameters that can be accepted by the Music.Clip object constructor.